package com.ruoyi.develop.goodsSaleTowork.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.goodsSaleTowork.domain.GoodsSaleTowork;
import com.ruoyi.develop.goodsSaleTowork.service.IGoodsSaleToworkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 派工产品Controller
 * @author qh
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/goodsSaleTowork/goodsSaleTowork")
public class GoodsSaleToworkController extends BaseController {
    @Autowired
    private IGoodsSaleToworkService goodsSaleToworkService;

    /**
     * 查询派工产品列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleTowork:query')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSaleTowork entity) {
        startPage();
        List<GoodsSaleTowork> list = goodsSaleToworkService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出派工产品列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleTowork:export')")
    @Log(title = "派工产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSaleTowork entity) {
        List<GoodsSaleTowork> list = goodsSaleToworkService.selectList(entity);
        ExcelUtil<GoodsSaleTowork> util = new ExcelUtil<GoodsSaleTowork>(GoodsSaleTowork. class);
        util.exportExcel(response, list, "派工产品数据");
    }

    /**
     * 获取派工产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleTowork:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(goodsSaleToworkService.selectById(id));
    }

    /**
     * 新增派工产品
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleTowork:add')")
    @Log(title = "派工产品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsSaleTowork entity) {
        return toAjax(goodsSaleToworkService.insert(entity));
    }

    /**
     * 修改派工产品
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleTowork:edit')")
    @Log(title = "派工产品", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody GoodsSaleTowork entity) {
        return toAjax(goodsSaleToworkService.update(entity));
    }

    /**
     * 删除派工产品
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleTowork:remove')")
    @Log(title = "派工产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(goodsSaleToworkService.deleteByIds(ids));
    }
}
